package com.example.mallproduct.feign;

import com.example.mallcommon.RestResult;
import com.example.mallproduct.api.domain.Product;
import com.example.mallproduct.fallback.ProductFeignFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author yangtao
 * @version 1.0
 * @description: 声明调用的提供者的name,这个name就是我们配置文件里设置的application.name fallbackFactory 能打印更多详细错误信息
 *     fallback
 * @date 2021/7/8 0008 23:48
 */
// @FeignClient(value = "mall-product",fallback = ProductServiceFallback.class)
@FeignClient(value = "mall-product", fallbackFactory = ProductFeignFallbackFactory.class)
public interface ProductFeign {
    /**
     * 指定调用提供者的哪个方法,可以发现这路径和注解以及参数完全就和ProductController中的一样，对的，就是拷贝过来的
     * 可以简单的理解成：@FeignClient+@GetMapping就能够对应到一个完整的请求路径，http://mall-product/product/{pid}
     *
     * @param pid
     * @return
     */
    @RequestMapping(value ="/product/{pid}",method = RequestMethod.GET)
    RestResult<Product> findByPid(@PathVariable("pid") Integer pid);

    /***
     * 扣减库存
     * @param pid
     * @param num
     */
    @RequestMapping(value ="/product/reduceInventory",method = RequestMethod.GET)
    void reduceInventory(@RequestParam("pid") Integer pid, @RequestParam("num")  int num);
}
